// pages/filing/choose-file.js
Page({

    data: {
        fileArr: [],
        haveCar: [{
                name: "行驶证",
                value: "行驶证",
                checked: false
            },
            {
                name: "登记证书",
                value: "登记证书",
            },
            {
                name: "买方身份证原件",
                value: "买方身份证原件",
            },
            {
                name: "卖方身份证复印件",
                value: "卖方身份证复印件",
            },
        ],
        noCar_entrust: [{
                name: "买方身份证原件",
                value: "买方身份证原件",
            },
            {
                name: "卖方身份证复原件",
                value: "卖方身份证复原件",
            },
        ],
        noCar_unentrust: [{
                name: "验车单",
                value: "验车单",
            },
            {
                name: "登记证书",
                value: "登记证书",
            },
            {
                name: "行驶证",
                value: "行驶证",
            },
            {
                name: "买方身份证原件",
                value: "买方身份证原件",
            },
            {
                name: "交易税票",
                value: "交易税票",
            },
            {
                name: "车牌",
                value: "车牌",
            },
        ],
    },

    onLoad: function(options) {
        Object.assign(options, getApp().filingData)
        this.setData(options)

        this.setFileArr()

    },
    setFileArr() {
        let {
            fileArr = [], carValue = '', entrustValue = ''
        } = this.data

        if (carValue == "有车") {
            fileArr.push(...this.data.haveCar)
        }
        if (carValue == "无车" && entrustValue == "有委托函") {
            fileArr.push(...this.data.noCar_entrust)
        }
        if (carValue == "无车" && entrustValue == "无委托函") {
            fileArr.push(...this.data.noCar_unentrust)
        }
        this.setData({
            fileArr
        })

    },
    checkboxChange: function(e) {
        var fileArr = this.data.fileArr,
            values = e.detail.value,
            checkAll = false,
            k = 0;
        for (var i = 0, lenI = fileArr.length; i < lenI; ++i) {
            fileArr[i].checked = false;
            for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
                if (fileArr[i].value == values[j]) {
                    fileArr[i].checked = true;
                    k++
                    break;
                }
            }
        }

        checkAll = k == fileArr.length

        this.setData({
            fileArr,
            checkAll
        });
    },

    next() {
        wx.navigateTo({
            url: './filing-form',
        })
    }
})